package com.itheima.sh.user.controller;

import com.itheima.sh.pojo.User;
import com.itheima.sh.request.dtos.UserQueryDTO;
import com.itheima.sh.response.vos.UserOrdersVO;
import com.itheima.sh.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("user")
@RefreshScope  // 刷新Spring 上下文
@Api(value = "用户管理API",tags = "用户管理API-USER",description = "用户管理提供用户的CRUD操作")
public class UserController {


    @Autowired
    UserService userService;

    @Value("${test.name}")
    private String name;


    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    @GetMapping("findUserById/{username}")
    @ApiOperation(value = "根据用户名查询用户信息")
//     @ApiParam(value = "用户名", required = true)
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "用户名", required = true),
//            @ApiImplicitParam(value = "用户名", required = true)
//    })
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "用户名", required = true)
//    })
    public User findUserById(@PathVariable("username")@ApiParam(value = "用户名", required = true) String username) {
        return userService.findUserById(username);
    }

//    /**
//     * 根据用户登录名查询订单列表
//     * @param username
//     *
//     * DTO：
//     * VO：
//     * POJO：
//     */
//    @GetMapping("findOrderByUserId/{username}")
//    public UserOrdersVO findOrderByUserId(@PathVariable("username") String username) {
//        return userService.findOrderByUserId(username);
//    }

    @Value("${server.port}")
    private String port;

    @PostMapping("findOrderByUserId")
    @ApiOperation(value = "根据用户名查询所属订单")
    public UserOrdersVO findOrderByUserId(@RequestBody UserQueryDTO userQueryDTO) {

        System.out.println("UserController PORT: " + port);
        System.out.println("name: " + name);

        return userService.findOrders(userQueryDTO);
    }

}
